package beans

import models.UserInfoM
import java.text.SimpleDateFormat

data class UserInfo(
        val nick_name: String?,
        val sign: String?,
        val avatar: String?,
        val sex: Int?,
        val birthday: String?,
        val stu_id: String?,
        val school: String?,
        val college: String?
) {
    companion object{
        fun fromModel(model: UserInfoM): UserInfo{
            val format = SimpleDateFormat("yyyy-MM-dd")
            val birthday = format.format(model.getTimestamp(UserInfoM.BIRTHDAY))
            return UserInfo(
                    nick_name = model[UserInfoM.NICK_NAME],
                    sign = model[UserInfoM.SIGN] ?: "",
                    avatar = model[UserInfoM.AVATAR] ?: "",
                    sex = model.getInt(UserInfoM.SEX),
                    birthday = birthday,
                    stu_id = model[UserInfoM.STU_ID] ?: "",
                    college = model[UserInfoM.COLLEGE] ?: "",
                    school = model[UserInfoM.SCHOOL] ?: ""
            )
        }
    }
}